layui.define(['form','tree','form'], function(exports){
    var $ = layui.$
    ,admin = layui.admin
    ,view = layui.view
    ,tree = layui.tree
    ,setter = layui.setter
    ,response = setter.response
    ,form = layui.form;

    var treeId = ""; 


    var obj = {
        /**
        * 创建树
        * @param id 表格id
        * @param url 请求地址
        * @param searchParam api参数
        * @param checkBox 是否显示checkBox
        * @param onlyIconControl 是否仅点加号展开
        * @param callback 回调函数
        */
        CreateTree :function (id, url, searchParam,checkBox,onlyIconControl,callback) {
            treeId = id;
            if(treeId == undefined || treeId == null || treeId == ''){
                treeId = 'layt-tree';
            }
            if(checkBox == undefined || checkBox == null){
                checkBox = true
            }
            
            admin.req({
                url: setter.apiUrl + url
                , type: 'Get'
                , data: searchParam
                , contentType: "application/json;charset=UTF-8"
                , success: function (res) {
                    tree.render({
                        elem: '#'+treeId
                        ,checkChirld:false
                        , id:treeId
                        , onlyIconControl: onlyIconControl
                        , data: res.data // 数据源
                        ,showCheckbox: checkBox //开启复选框
                        , showLine: true  //是否开启连接线
                        ,click: function (obj) {
                            callback(obj);
                            
                        }
                      });
                }
              });

        }
        
    }

    exports('layTree', obj)

});